<template>
  <div class="container">
    <div class="user">
      <van-image class="img" :src="userInfo.avatar"></van-image>
      <div class="text">{{ userInfo.nickname}}</div>
    </div>
    <div class="order">
      <div class="top">
        <div class="text1">
          我的订单
        </div>
        <div class="text2">
          全部
        </div>
      </div>
      <div class="bottom">
        <div class="item">
          <van-image @click="goOrder(1)"
                     width="48"
                     height="48"
                     src="/images/od_10.png"/>
          <div>待支付</div>
        </div>
        <div class="item">
          <van-image @click="goOrder(2)"
                     width="48"
                     height="48"
                     src="/images/od_20.png"/>
          <div>待服务</div>
        </div>
        <div class="item">
          <van-image @click="goOrder(3)"
                     width="48"
                     height="48"
                     src="/images/od_30.png"/>
          <div>已完成</div>
        </div>
        <div class="item">
          <van-image @click="goOrder(4)"
                     width="48"
                     height="48"
                     src="/images/od_40.png"/>
          <div>已取消</div>
        </div>
      </div>

    </div>

    <van-button @click="logout" class="submit" type="danger" size="large">
      退出登陆
    </van-button>
  </div>
</template>

<script setup>
import { useRouter, useRoute} from 'vue-router'
import {getCurrentInstance, onMounted, reactive, computed, ref} from "vue";

const { proxy } = getCurrentInstance();
const router = useRouter();
const route = useRoute();

const userInfo = reactive({})

// 登出
const logout = () => {
  // 清理token
  localStorage.removeItem('h5_token');
  // 跳转回登陆页面
  router.push('/login')
}

onMounted(async () => {

  // 用户信息
  const { data } = await proxy.$api.userinfo();
  Object.assign(userInfo, data.data);
  console.log('userInfo',userInfo);

});
const emit = defineEmits(['child-event']);

const goOrder = (active) => {
  // 触发自定义事件，通知父组件
  emit('child-event', 'order');
  // 通过 $root 触发自定义事件
  router.push(`/order?active=${active}`)
}


</script>

<style lang="less" scoped>
.container {
  background-color: #f0f0f0;
  height: 100vh;
  overflow: hidden;
  .user {
    width: 95%;
    height: 200px;
    background-color: #fff;
    text-align: center;
    border-radius: 10px;
    margin: 10px;
    .img {
      margin-top: 30px;
    }
    .text {
      line-height: 30px;
      font-weight: bold;
    }
  }
  .order {
    width: 90%;
    margin: 10px;
    border-radius: 5px;
    background-color: #fff;
    padding: 10px;
    .top {
      margin: 10px;
      line-height: 50px;
      display: flex;
      justify-content: space-between;
      .text1 {
        color: #333;
      }
      .text2 {
        color: #999;
      }
      border-bottom: 0.5px solid #f5f5f5;
    }
    .bottom {
      padding: 10px;
      display: flex;
      justify-content: space-around;
      .item {
        font-size: 14px;
        color: #999;
      }
    }
  }
  .foot {
    margin: 0 10px;
    padding: 10px;
    line-height: 50px;
    background-color: #fff;
    .foot1,
    .foot2 {
      display: flex;
      justify-content: space-between;
      color: #555;
    }
    .foot1 {
      border-bottom: 0.5px solid #f5f5f5;
    }
  }
  .quit {
    width: 90%;
    margin: 20px;
  }
  .quit_text {
    margin: 20px 0;
    text-align: center;
  }
}
</style>
